package cn.zhong5.changzhoulocaltax;

import android.util.Log;

import com.socks.library.KLog;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import com.tencent.smtt.sdk.QbSdk;
import com.tencent.smtt.sdk.TbsListener;

import cn.zhong5.changzhoulocaltax.base.BaseApplication;
import cn.zhong5.changzhoulocaltax.module.web.WebViewActivity;

/**
 * Created by Sunman on 2017-12-4 0004.
 */

public class CZLocalTaxApp extends BaseApplication
{
    @Override
    public void onCreate()
    {
        super.onCreate();

        //**************************************相关第三方SDK的初始化等操作*************************************************
        KLog.init(BuildConfig.IS_DEBUG);                                                        //初始化KLog
        initBugly();
        initTBS ();                                                                             //初始化腾讯X5 WebView
    }

    private void initBugly() {
        Beta.initDelay = 6 * 1000;
        Beta.autoCheckUpgrade = true;
        Beta.canShowUpgradeActs.add(WebViewActivity.class);
        Bugly.init(getApplicationContext(), "9e4244dcbd", BuildConfig.IS_DEBUG);                //升级
    }

    private void initTBS () {
        //搜集本地tbs内核信息并上报服务器，服务器返回结果决定使用哪个内核。
        QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {

            @Override
            public void onViewInitFinished(boolean arg0) {
                // TODO Auto-generated method stub
                //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
                Log.d("app", " onViewInitFinished is " + arg0);
            }

            @Override
            public void onCoreInitFinished() {
                // TODO Auto-generated method stub
            }
        };

        QbSdk.setTbsListener(new TbsListener() {
            @Override
            public void onDownloadFinish(int i) {
                KLog.i("onDownloadFinish");
            }

            @Override
            public void onInstallFinish(int i) {
                KLog.i("onInstallFinish");
            }

            @Override
            public void onDownloadProgress(int i) {
                KLog.i("onDownloadProgress:" + i);
            }
        });

        //x5内核初始化接口
        QbSdk.initX5Environment(getApplicationContext(),  cb);
    }

}
